
#include "gtest/gtest.h"

#include "ChainHashTable.h"

class Element {
public:
    operator long() const { return key; }

    void SetKV( int k, int v )
    {
        key = k;
        data = v;
    }

    void Output( ostream& out ) const
    {
        out << "[" << key << ":" << data << "]";
    }

    int key;
    int data;
};

ostream& operator<<( ostream& out, const Element& x )
{
    x.Output(out);

    return out;
}

TEST( ChainHashTableTest, Simple )
{
    Element e;
    ChainHashTable<Element, long> h(11);

    // 这其中有 = 操作的
    e.SetKV( 80, 180 );
    h.Insert( e );
    e.SetKV( 40, 140 );
    h.Insert( e );
    e.SetKV( 65, 165 );
    h.Insert( e );
    e.SetKV( 58, 158 );
    h.Insert( e );
    e.SetKV( 24, 124 );
    h.Insert( e );
    e.SetKV( 2, 102 );
    h.Insert( e );
    e.SetKV( 13, 113 );
    h.Insert( e );
    e.SetKV( 46, 146 );
    h.Insert( e );
    e.SetKV( 16, 116 );
    h.Insert( e );
    e.SetKV( 7, 107 );
    h.Insert( e );
    e.SetKV( 21, 112 );
    h.Insert( e );

    h.Delete( 2, e );
    h.Delete( 16, e );
    h.Delete( 24, e );
    h.Delete( 80, e );

    EXPECT_THROW( h.Delete( 87, e ), class BadInput );
}

#include "main_stub.h"

